package com.csii.ssm.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class SystemSessionListener implements HttpSessionListener {

    private static final Logger logger = LoggerFactory.getLogger(SystemSessionListener.class);

    @Override
    public void sessionCreated(HttpSessionEvent event) {
        logger.debug("===新建Session===" + event.getSession().getId());
        //TODO:客户要求session用不超时：
//        event.getSession().setMaxInactiveInterval(-1);//设置单位为秒，设置为-1永不过期。
        SystemSessionContext.addSessoin(event.getSession());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        SystemSessionContext.removeSession(event.getSession());
        logger.warn("===移除了Session===" + event.getSession().getId());
    }

}
